﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;


namespace MemoryGames.Games.SearchDifferences
{
	/// <summary>
	/// Interaction logic for Maintenance.xaml
	/// </summary>
	public partial class Maintenance : UserControl, IGameControl
	{
		#region "Events"
		public event MainForm.MainFormRestartDelegate MainFormRestart;
		#endregion

		#region "MemberVariables"
		private SearchDifferences sde = new SearchDifferences();
		private SearchDifferencesTableAdapters.PuzzleTableAdapter pta = new SearchDifferencesTableAdapters.PuzzleTableAdapter();
		private SearchDifferencesTableAdapters.AnswerTableAdapter ata = new SearchDifferencesTableAdapters.AnswerTableAdapter();
		#endregion

		#region "Constructors"
		public Maintenance()
		{
			InitializeComponent();
            
		}
		#endregion

		#region "Methods"
		public bool Initialize()
		{
			Background = null;

			BindData();

			return true;
		}

		private void BindData()
		{
			pta.Fill(sde.Puzzle);
			ata.Fill(sde.Answer);

			lvItems.DataContext = sde.Puzzle;
		}
		#endregion

		private void lvItems_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			cPuzzle.DataContext = lvItems.SelectedItem;
            
		}

		private void New_Click(object sender, RoutedEventArgs e)
		{
			SearchDifferences.PuzzleRow pr = sde.Puzzle.NewPuzzleRow();
			pr.Name = "New";
			sde.Puzzle.AddPuzzleRow(pr);
			lvItems.SelectedValue = "New";
		}

		private void Delete_Click(object sender, RoutedEventArgs e)
		{

		}

		private void btnInCompleteFile_Click(object sender, RoutedEventArgs e)
		{
			//Microsoft.Win32.OpenFileDialog ofd = new OpenFileDialog();
			//if (ofd.ShowDialog() == true )
			//{
			//    BitmapImage bmp = new BitmapImage();
			//    bmp.BeginInit();
			//    bmp.UriSource =new Uri(ofd.FileName);
			//    bmp.EndInit();
			//    ((MemoryGames.SearchDifferences.SearchDifferences.PuzzleRow)
			//     ((System.Data.DataRowView) cPuzzle.DataContext).Row).CompleteImage =System.IO.FileInfo() ofd.FileName


			//    //cPuzzle.DataContext
			//    imgInComplete.Source = bmp;
			//}

		}

		private void btnCompleteFile_Click(object sender, RoutedEventArgs e)
		{

		}

		private void btnCancel_Click(object sender, RoutedEventArgs e)
		{
			this.MainFormRestart.Invoke();
		}
	}
}